package com.happypets.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.happypets.model.PageBean;
import com.happypets.model.PetBean;
import com.happypets.services.PetService;
import com.happypets.servicesImpl.PetServiceImpl;

/**
 * Servlet implementation class DogServlet
 */
public class DogServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public DogServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		System.out.println("------dogServlet start");
		

		
		//过滤器
		//进行相关处理
		//添加评论
		String path = request.getContextPath();

		HttpSession session = request.getSession();
				
		session.setAttribute("dogFlag", "yes");
				
		PetService petService = new PetServiceImpl();
		
		String id = (String)request.getParameter("id");
				
		
		if(id == null){
			response.sendRedirect(path+"/web/error.html");
		}else{
		
			PetBean pet = petService.getPetBean(id);
		
			session.setAttribute("dogPet", pet);
		
			response.sendRedirect(path+"/web/dog.jsp?id="+id);
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
